/* vim: set ts=2 et sw=2 cindent fo=qroca: */

package com.globant.google.mendoza.malbec;

import java.util.Date;

import com.globant.google.mendoza.malbec.schema._2.
AuthorizationAmountNotification;
import com.globant.google.mendoza.malbec.schema._2.Money;
import com.globant.google.mendoza.malbec.schema._2.NewOrderNotification;
import com.globant.google.mendoza.malbec.schema._2.RiskInformationNotification;

/** The GBuy order notification listener.
 */
public interface OrderListener {

  /** Called when a new message is received, before the acknowledge is sent to
   * GBuy.
   *
   * @param command The command name. This is the top level xml node name.
   *
   * @param orderNumber The GBuy order number.
   *
   * @param timestamp The notification timestamp.
   */
  void receiveMessage(final String command, final String orderNumber, final
      Date timestamp);

  /** Called when a buyer places an order.
   *
   * @param order The order initialized to talk to GBuy.
   *
   * @param timestamp Time and date of message in ISO 8601 format.
   *
   * @param newOrderNotification The data included in the new order
   * notification.
   */
  void newOrder(final Order order, final Date timestamp, final
      NewOrderNotification newOrderNotification);

  /** Called when GBuy sends the risk information notification.
   *
   * @param order The order initialized to talk to GBuy.
   *
   * @param timestamp Time and date of message in ISO 8601 format.
   *
   * @param riskInformationNotification The buyer's risk information.
   */
  void riskInformation(final Order order, final Date timestamp,
      final RiskInformationNotification riskInformationNotification);

  /** Called when the GBuy order changes state.
   *
   * @param order The order initialized to talk to GBuy.
   *
   * @param timestamp Time and date of message in ISO 8601 format.
   *
   * @param newFulfillmentState Order's current fulfillment state.
   *
   * @param newFinancialState Order's current financial state.
   *
   * @param oldFulfillmentState Fulfillment state before this state change.
   *
   * @param oldFinancialState Financial state before this state change.
   *
   * @param reason Description of state change (not always used).
   */
  void stateChanged(final Order order, final Date timestamp,
      final String newFulfillmentState, final String newFinancialState,
      final String oldFulfillmentState, final String oldFinancialState,
      final String reason);

  /** Called when all or part of the funds for the order are captured
   * (charged).
   *
   * @param order The order initialized to talk to GBuy.
   *
   * @param timestamp Time and date of message in ISO 8601 format.
   *
   * @param latest Value of the most recent charge on this order.
   *
   * @param total Total value charged on this order.
   */
  void chargeAmount(final Order order, final Date timestamp,
      final Money latest, final Money total);

  /** When you request a refund by sending a refund-order message, GBuy sends
   * you a refund-amount-notification.
   *
   * @param order The order initialized to talk to GBuy.
   *
   * @param timestamp Time and date of message in ISO 8601 format.
   *
   * @param latest Value of the most recent charge on this order.
   *
   * @param total Total value charged on this order.
   */
  void refundAmount(final Order order, final Date timestamp,
      final Money latest, final Money total);

  /** When the buyer initiates a chargeback against the order, and GBuy
   * approves the chargeback, GBuy sends you a chargeback-amount-notification.
   *
   * @param order The order initialized to talk to GBuy.
   *
   * @param timestamp Time and date of message in ISO 8601 format.
   *
   * @param latest Value of the most recent charge on this order.
   *
   * @param total Total value charged on this order.
   */
  void chargebackAmount(final Order order, final Date timestamp,
      final Money latest, final Money total);

  /** Authorization Amount Notification.
   *
   * @param order The order initialized to talk to GBuy.
   *
   * @param timestamp Time and date of message in ISO 8601 format.
   *
   * @param authorizationAmountNotification The authorization amount
   * notification.
   */
  void authorizationAmount(final Order order, final Date timestamp,
      final AuthorizationAmountNotification authorizationAmountNotification);

  /** Called when an unrecognized message is received.
   *
   * @param message The complete received message.
   */
  void unknown(final String message);

}

